package com.cskaoyan.market.controller;

import com.cskaoyan.market.service.WxCartService;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: 付诚
 * @Date: 2024/5/21 19:29
 * @Description:
 */
@RestController
//@RequestMapping("/wx/cart")
public class WxCartController {
    @Autowired
    private WxCartService wxCartService;


    @PostMapping("/update")
    public Object update(@RequestBody Map<String,Integer> map) {

        Integer goodsId = map.get("goodsId");
        Integer id = map.get("id");
        Integer number = map.get("number");
        Integer productId = map.get("productId");

        Integer state = 0;
        state = wxCartService.update(goodsId,id,number,productId);

        if(state == -1){
            return ResponseUtil.fail(401,"商品库存不足");
        }

        return ResponseUtil.ok();

    }

    @PostMapping("/delete")
    public Object delete(@RequestBody Map<String, List<Integer>> prodectIds){

        Map<String, Object> data = wxCartService.delete(prodectIds);

        return ResponseUtil.ok(data);
    }

}
